package com.quan.mall.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quan.commons.core.bean.R;
import com.quan.commons.core.biz.support.MyBaseController;
import com.quan.commons.core.utils.*;
import com.quan.system.commons.vo.SysUserVo;
import com.quan.commons.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

import com.quan.mall.commons.vo.WmsAgentInfoVo;
import com.quan.mall.entity.WmsAgentInfo;
import com.quan.mall.service.WmsAgentInfoService;


/**
 * 仓库-代理商信息
 *
 * @author yhaoquan
 * @email yhaoquan@163.com
 * @date 2021-04-07 22:27:21
 */
@Slf4j
@Api(tags = "仓库-代理商信息")
@RestController
@RequestMapping("/mall/wmsagentinfo")
public class WmsAgentInfoController extends MyBaseController {

    @Autowired
    private WmsAgentInfoService service;

    /**
     * 保存
     * @param vo
     * @return
     */
    @SysLog("保存")
    @PostMapping("save")
    public R save(@Valid @RequestBody WmsAgentInfoVo vo) {
        this.service.save(vo);
        return R.ok();
    }

    /**
     * 修改
     * @param vo
     * @return
     */
    @SysLog("修改")
    @PostMapping("update")
    public R update(@Valid @RequestBody WmsAgentInfoVo vo) {
        this.service.updateById(vo);
        return R.ok();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @SysLog("删除")
    @PostMapping("delete")
    public R delete(@RequestBody Long[] ids) {
        if (null != ids && ids.length > 0) {
            this.service.removeByIds(Arrays.asList(ids));
            return R.ok();
        } else {
            return R.failure();
        }
    }

    /**
     * 多条件查询信息详情
     * @param vo
     * @return
     */
    @SysLog("查询详情")
    @GetMapping("/info")
    public R info(WmsAgentInfoVo vo) {
        QueryWrapper<WmsAgentInfo> queryWrapper = new QueryWrapper<WmsAgentInfo>(vo);
        WmsAgentInfo wmsAgentInfo = this.service.getOne(queryWrapper);
        return R.ok().put("data", wmsAgentInfo);
    }

    /**
     * 根据ID查询信息详情
     * @param {id}
     * @return
     */
    @SysLog("查询详情")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        WmsAgentInfo wmsAgentInfo = this.service.getById(id);
        return R.ok().put("data", wmsAgentInfo);
    }

    /**
     * 列表查询
     * @param vo
     * @return
     */
    @SysLog("查询列表")
    @GetMapping(value = "list")
    public Object list(WmsAgentInfoVo vo) {
        List<WmsAgentInfoVo> list = this.service.queryList(new PageUtils(request), vo);
        return R.ok().put("data", list);
    }

    /**
     * 分页查询
     * @param vo
     * @return
     */
    @SysLog("分页查询")
    @GetMapping(value = "page")
    public R queryPage(WmsAgentInfoVo vo) {
        PageUtils page = this.service.queryPage(new PageUtils(request), vo);
        return R.ok().put("data", page);
    }

}
